<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/5/22
  Time: 13:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>找兼职</title>
</head>
<body>
<style type="text/css">
    table{
        border-collapse: collapse;
    }
    td{
        border: 1px solid #000;
        padding: 10px;
    }
</style>
<jsp:include page="header.jsp"></jsp:include><br>
<table>
    <thead>
    <tr>
        <td>编号</td>
        <td>兼职名称</td>
        <td>兼职要求</td>
        <td>发布人及信息</td>
        <td>报名</td>
        <td>请求代班</td>
    </tr>
    </thead>
    <tbody>
    <%
        class Part_time_job{
            int id;
            String ptjname;           //ptj(part-time job)
            String ptjrequire;
            String issuer;
        }
        List<Part_time_job> list=new ArrayList<>();


        //3+1
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;

        String sql="select * from ptj";

        Class.forName("com.mysql.jdbc.Driver");

        connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/part_time_job?serverTimezone=UTC",
                "root",
                "123456"
        );

        statement =connection.createStatement();
        resultSet =statement.executeQuery(sql);


        while (resultSet.next()){
            int id = resultSet.getInt(1);
            String ptjname = resultSet.getString(2);
            String ptjrequire = resultSet.getString(3);
            String issuer=resultSet.getString(4);

            Part_time_job u = new Part_time_job();
            u.id=id;
            u.ptjname=ptjname;
            u.ptjrequire=ptjrequire;
            u.issuer=issuer;
            list.add(u);
        }
        resultSet.close();
        statement.close();
        connection.close();
        for (Part_time_job user:list){
            out.write("<tr><td>"+user.id+ "</td>" +
                    "<td>"+user.ptjname+ "</td>" +
                    "<td>"+user.ptjrequire+ "</td>"+
                    "<td>"+user.issuer+"</td>"+
                    "<td><a href='apply.jsp'>报名</a></td>"+
                    "<td><a href='replaceHandler.jsp'>代班</a></td></tr>");
        }
    %>

    </tbody>
</table>
</body>
</html>
